package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowOpertion implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("请输入要借阅书的书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        System.out.println("请输入要借阅书的作者：");
        String author = scanner.nextLine();

        System.out.println("请输入要借阅书的类型：");
        String type = scanner.nextLine();

        System.out.println("请输入要借阅书的价格：");
        int price = scanner.nextInt();

        Book book = new Book(name,author,type,price);

        //看这本书是否有并未被借出，有就改状态
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            if(bookList.getBooks()[i].equals(book)
            && !bookList.getBooks()[i].isBorrowed()){

                bookList.getBooks()[i].setBorrowed(true);
                System.out.println("借阅成功");
                return;

            } else if (bookList.getBooks()[i].equals(book)
                    && bookList.getBooks()[i].isBorrowed()) {
                System.out.println("该书以被借出");
                return;
            }
        }
        System.out.println("没有该书");
    }
}
